package com.wzh.stream;

import cn.hutool.core.collection.ArrayIter;
import com.wzh.po.User;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
 * @description:
 * @author: WZH
 * @time: 2021/12/28 19:49
 */

public class Demo2 {

    public static void main(String[] args) {

        ArrayList<User> users = new ArrayList<>();

        User user1 = new User("张三", 19, "河南", null);
        User user2 = new User("李四", 19, "河南", null);
        User user3 = new User("王五", 15, "河南", null);
        User user4 = new User("赵六", 109, "河南", null);
        User user5 = new User("赵六", 109, "河南", null);

        users.add(user1);
        users.add(user2);
        users.add(user3);
        users.add(user4);
        users.add(user5);


        ArrayList<User> collect = users.stream().collect(
                Collectors.collectingAndThen(
                        Collectors.toCollection(
                                () -> new TreeSet<User>(Comparator.comparing(User::getAge))
                        ), ArrayList<User>::new));

        for (User s : collect) {
            System.out.println(s.toString());
        }


    }
}
